#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: client.py 
@version:
@time: 2022/06/22 
"""
import socket
import time

MaxBytes = 1024 * 1024
host = '127.0.0.1'
port = 11224
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
    client.settimeout(30)
    addr = (host, port)
    client.connect(addr)
    while True:
        inputData = input()  # 等待输入数据
        if (inputData == "quit"):
            print("quit")
            break
        sendBytes = client.sendto(inputData.encode(), addr)
        if sendBytes <= 0:
            continue
        recData, addr2 = client.recvfrom(MaxBytes)
        if not recData:
            print('rec data is null, break')
            break
        localTime = time.asctime(time.localtime(time.time()))
        print(localTime, )
        print('receive byte length:', len(recData))
        print('receive byte data:', recData.decode())
        client.send(f'get data: {recData.decode()}'.encode())
